<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>商品参数设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加商品参数{else}<i class="fa fa-pencil"></i> 编辑商品参数{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form form-label-w6" lay-filter="">
						<input type="hidden" name="info[id]" value="{$info['id']}">
						<div class="layui-form-item">
							<label class="layui-form-label">参数名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[name]" value="{$info.name}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
						</div>
						<!-- <div class="layui-form-item">
							<label class="layui-form-label">图标：</label>
							<input type="hidden" name="info[pic]" id="pic" class="layui-input" value="{$info.pic}">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="pic" upload-preview="picPreview" onclick="uploader(this)">上传图片</button>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：400×400像素</div>
							<div id="picPreview" style="float:left;padding-top:10px;margin-left:130px;clear: both;">
								<div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info.pic}"/></div></div>
							</div>
						</div> -->
						<div class="layui-form-item">
							<label class="layui-form-label">适用分类：</label>
							<div class="layui-input-inline" style="width:360px">
								<select name="info[cid]" id="cid" xm-select="selectCid" xm-select-max="" xm-select-search >
									<option value="">--请选择--</option>
									{foreach $clist as $cv}
									<option value="{$cv['id']}" {if in_array($cv['id'],$info['cid'])}selected{/if}>{$cv['name']}</option>
									{foreach $cv['child'] as $k=>$v}
									{if $k < count($cv['child'])-1}
									<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>
									{else}
									<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>
									{/if}
									{foreach $v['child'] as $k2=>$v2}
									{if $k2 < count($v['child'])-1}
									<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>
									{else}
									<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>
									{/if}
									{/foreach}
									{/foreach}
									{/foreach}
								</select>
							</div>
							<div class="layui-form-mid layui-word-aux">商品编辑中，会使用商品对应的分类参数+未关联分类参数</div>
						</div>

						
						<div class="layui-form-item">
							<label class="layui-form-label">参数类型：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="radio" name="info[type]" value="0" title="输入文本" {if !$info['id'] || $info['type']==0}checked{/if} lay-filter="settype">
								<input type="radio" name="info[type]" value="1" title="单项选择" {if $info['type']==1}checked{/if} lay-filter="settype">
								<input type="radio" name="info[type]" value="2" title="多项选择" {if $info['type']==2}checked{/if} lay-filter="settype">
							</div>
						</div>

						<div id="type12_div" style="{if !$info['id'] || $info['type']==0}display:none{/if}">
							{if $info['params']}
							{foreach $info['params'] as $k=>$v}
							<div class="layui-form-item">
								<label class="layui-form-label">{if $k==0}设置参数：{/if}</label>
								<div class="layui-input-inline"><input type="text" name="params[]" value="{$v}" class="layui-input"></div>
								{if $k==0}
								<button type="button" class="layui-btn layui-btn-primary" onclick="adddata()">新增</button>
								{else}
								<button type="button" class="layui-btn layui-btn-primary" onclick="deldata(this)">删除</button>
								{/if}
							</div>
							{/foreach}
							{else}
							<div class="layui-form-item">
								<label class="layui-form-label">设置参数：</label>
								<div class="layui-input-inline"><input type="text" name="params[]" value="" class="layui-input"></div>
								<button type="button" class="layui-btn layui-btn-primary" onclick="adddata()">新增</button>
							</div>
							{/if}
						</div>
						<script>
						function adddata(){
							var html = '';
							html+='<div class="layui-form-item">';
							html+='	<label class="layui-form-label"></label>';
							html+='	<div class="layui-input-inline"><input type="text" name="params[]" value="" class="layui-input"></div>';
							html+='	<button type="button" class="layui-btn layui-btn-primary" onclick="deldata(this)">删除</button>';
							html+='</div>';
							$('#type12_div').append(html);
						}
						function deldata(obj){
							$(obj).parent().remove();
						}
						</script>
						<div class="layui-form-item">
							<label class="layui-form-label">提示信息：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[tips]" value="{$info.tips}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;"></div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">是否必填：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[is_required]" value="0" title="否" {if !$info['id'] || $info['is_required']==0}checked{/if}>
								<input type="radio" name="info[is_required]" value="1" title="是" {if $info['is_required']==1}checked{/if}>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">序号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sort]" value="{$info.sort}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">用于排序,越大越靠前</div>
						</div>
						
						<div class="layui-form-item">
							<label class="layui-form-label">状态：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[status]" value="1" title="开启" {if !$info['id'] || $info['status']==1}checked{/if}>
								<input type="radio" name="info[status]" value="0" title="关闭" {if $info['id'] && $info['status']==0}checked{/if}>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"></label>
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
				</div>
			</div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
	layui.form.on('radio(settype)', function(data){
		if(data.value == '0'){
			$('#type12_div').hide();
		}else{
			$('#type12_div').show();
		}
	})
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>